package com.teradyne.phoenix.client.mvp;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.core.client.GWT;
import com.google.gwt.place.shared.Place;
import com.teradyne.phoenix.client.activities.RolesActivity;
import com.teradyne.phoenix.client.activities.UserActivity;
import com.teradyne.phoenix.client.factory.AppFactory;
import com.teradyne.phoenix.client.places.RolesPlace;
import com.teradyne.phoenix.client.places.UserPlace;

public class AppActivityMapper implements ActivityMapper {

	private AppFactory appFactory;

	/**
	 * AppActivityMapper associates each Place with its corresponding
	 * {@link Activity}
	 * 
	 * @param browserFactory
	 *            Factory to be passed to activities
	 */
	public AppActivityMapper(AppFactory appFactory) {
		super();
		this.appFactory = appFactory;
	}

	/**
	 * Map each Place to its corresponding Activity. This would be a great use
	 * for GIN.
	 */
	@Override
	public Activity getActivity(Place place) {
		GWT.log("Place called: " + place);
		if (place instanceof UserPlace) {
			return new UserActivity(appFactory);
		} else if (place instanceof RolesPlace) {
			return new RolesActivity(appFactory);
		}

		return null;
	}

}